@@ -2,6 +2,16 @@ Revision history for Perl extension Plack
Take a look at http://github.com/miyagawa/Plack/issues for the planned changes before 1.0 release.
+0.9972 Thu Feb 24 10:50:01 PST 2011
+ - Fixed the Plack::Runner docs to avoid the cargo cult issue of __FILE__ eq $0
+ - Added a silly check to give warnings if the idiom __FILE__ eq $0 is used in .psgi
+
+0.9971 Wed Feb 23 14:02:35 PST 2011
+ [INCOMPATIBLE CHANGES]
+ - Localize $0 to the given .psgi path when evaluating it in Plack::Util::load_psgi()
+ This fixes the unexpected values and/or crashes with Starman when your application
+ uses FindBin module.
+
0.9970 Tue Feb 22 08:35:50 PST 2011
- Apache2: Fixed a bug where dispatcher fails to parse first path when it begins with two or
more slashes (clkao)
@@ -260,6 +260,7 @@ t/Plack-Test/hello_server.t
t/Plack-Test/suite.t
t/Plack-Util/bad.psgi
t/Plack-Util/bad2.psgi
+t/Plack-Util/bin/findbin.psgi
t/Plack-Util/error.psgi
t/Plack-Util/foreach.t
t/Plack-Util/headers.t
@@ -40,4 +40,4 @@ resources:
homepage: http://plackperl.org
license: http://dev.perl.org/licenses/
repository: git://github.com/miyagawa/Plack.git
-version: 0.9970
+version: 0.9972
@@ -2,7 +2,7 @@ package Plack::Request;
use strict;
use warnings;
use 5.008_001;
-our $VERSION = '0.9970';
+our $VERSION = '0.9972';
$VERSION = eval $VERSION;
use HTTP::Headers;
@@ -1,7 +1,7 @@
package Plack::Response;
use strict;
use warnings;
-our $VERSION = '0.9970';
+our $VERSION = '0.9972';
$VERSION = eval $VERSION;
use Plack::Util::Accessor qw(body status);
@@ -298,14 +298,21 @@ other backends like L<Plack::Handler::Apache2> or mod_psgi.
If you I<really> want to make your C<.psgi> runnable as a standalone
script, you can do this:
- # foo.psgi
- if (__FILE__ eq $0) {
+ my $app = sub { ... };
+
+ unless (caller) {
require Plack::Runner;
- Plack::Runner->run(@ARGV, $0);
+ my $runner = Plack::Runner->new;
+ $runner->parse_options(@ARGV);
+ return $runner->run($app);
}
- # This should always come last
- my $app = sub { ... };
+ return $app;
+
+B<WARNING>: this section used to recommend C<if (__FILE__ eq $0)> but
+it's known to be broken since Plack 0.9971, since C<$0> is now
+I<always> set to the .psgi file path even when you run it from
+plackup.
=head1 SEE ALSO
@@ -1,6 +1,6 @@
package Plack::Server::ServerSimple;
use strict;
-our $VERSION = '0.9970';
+our $VERSION = '0.9972';
$VERSION = eval $VERSION;
use parent qw(Plack::Handler::HTTP::Server::Simple);
@@ -105,6 +105,10 @@ sub _load_sandbox {
my $_package = $_file;
$_package =~ s/([^A-Za-z0-9_])/sprintf("_%2x", unpack("C", $1))/eg;
+ _file_zero_check($_file) if $ENV{PLACK_ENV} eq 'development';
+
+ local $0 = $_file; # so FindBin etc. works
+
return eval sprintf <<'END_EVAL', $_package;
package Plack::Sandbox::%s;
{
@@ -115,6 +119,27 @@ package Plack::Sandbox::%s;
END_EVAL
}
+sub _file_zero_check {
+ my $file = shift;
+ open my $fh, "<", $file or return;
+
+ my $code = join '', <$fh>;
+ if ($code =~ /(__FILE__\s+eq\s+\$0|\$0\s+eq\+__FILE__)/) {
+ warn <<WARNING
+Your PSGI file ($file) seems to use the following idiom, which is known to be broken since Plack 0.9971:
+
+ if ($1) {
+ called_from_cmdline();
+ }
+
+because now \$0 is _always_ localized to the PSGI file path you're evaluating. You should switch to other alternatives such as `unless (caller) {}`. See http://bit.ly/psgi-file-0 for details.
+
+This friendly warning and the code to generate this runs only when the Plack environment (-E) is set to 'development', and will go away in the next major release of Plack.
+
+WARNING
+ }
+}
+
sub load_psgi {
my $stuff = shift;
@@ -3,7 +3,7 @@ package Plack;
use strict;
use warnings;
use 5.008_001;
-our $VERSION = '0.9970';
+our $VERSION = '0.9972';
$VERSION = eval $VERSION;
1;
@@ -0,0 +1,2 @@
+use FindBin;
+sub { [ 200, [ "Content-Type", "text/plain" ], [ "$FindBin::Bin" ] ] };
@@ -45,4 +45,11 @@ use Test::More;
unlike $@, qr/Died/;
}
+{
+ my $app = Plack::Util::load_psgi("t/Plack-Util/bin/findbin.psgi");
+ test_psgi $app, sub {
+ like $_[0]->(GET "/")->content, qr!t[/\\]Plack-Util[/\\]bin$!;
+ }
+}
+
done_testing;